package com.flyou.ccnucenter.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.flyou.ccnucenter.R;
import com.flyou.ccnucenter.adapter.WelcomePagerAdapter;
import com.flyou.ccnucenter.view.jazzyviewpager.JazzyViewPager;
import com.flyou.ccnucenter.widget.viewpagerindicator.CirclePageIndicator;

public class WelcomePager extends Activity {
    private CirclePageIndicator indicator;
    private JazzyViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 设置满屏，不含系统状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // 设置满屏，不含软件标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_welcome_pager);
        viewPager = (JazzyViewPager) findViewById(R.id.JazzyViewPager);

        viewPager.setTransitionEffect(JazzyViewPager.TransitionEffect.Tablet);//设置切换动画
        viewPager.setPageMargin(30);//两个页面之间的间距
        viewPager.setFadeEnabled(true);//有淡入淡出效果
        viewPager.setOutlineEnabled(true);//有边框
        viewPager.setOutlineColor(0xff0000ff);//边框颜色
        viewPager.setAdapter(new WelcomePagerAdapter(viewPager, WelcomePager.this));
        viewPager.setOnPageChangeListener(onPageChangeLsitener);

        indicator = (CirclePageIndicator) findViewById(R.id.indicator);
        indicator.setViewPager(viewPager);
        indicator.setOnPageChangeListener(onPageChangeLsitener);
        indicator.setFillColor(getResources().getColor(R.color.white));
        indicator.setStrokeColor(getResources().getColor(R.color.white));
        indicator.setRadius(8);
        viewPager.setCurrentItem(0);
    }

    //    当pager改变的监听
    ViewPager.OnPageChangeListener onPageChangeLsitener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
//            Toast.makeText(WelcomePager.this,"position"+position+"length"+WelcomePagerAdapter.guideId.length,Toast.LENGTH_SHORT).show();
            if (position == WelcomePagerAdapter.guideId.length-1) {
                findViewById(R.id.enter).setVisibility(View.VISIBLE);
            }
            else{
                findViewById(R.id.enter).setVisibility(View.GONE);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    };

    public void enter(View view) {

        Intent intent = new Intent(WelcomePager.this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}

